package com.freewater.cargotracker.domain.model.paint;

import org.apache.commons.lang3.Validate;

import java.util.ArrayList;
import java.util.List;

public class MixedPaint implements Paint {

    private List<Paint> stockConstituents = new ArrayList<>();

    private double volume = 0;

    private PigmentColor color = new PigmentColor(0, 0, 0);

    public MixedPaint() {

    }

    @Override
    public double getVolume() {
        return volume;
    }

    @Override
    public PigmentColor getColor() {
        return color;
    }

    public List<Paint> getStockConstituents() {
        return stockConstituents;
    }

    public void mixIn(Paint other) {
        Validate.notNull(other, "Paint is required");
        this.volume = this.volume + other.getVolume();
        double ratio = other.getVolume() / this.volume;
        this.color = color.mixedWith(other.getColor(), ratio);
        stockConstituents.add(other);
    }

    @Override
    public String toString() {
        final StringBuffer sb = new StringBuffer("MixedPaint{");
        sb.append("stockConstituents=").append(stockConstituents);
        sb.append(", volume=").append(volume);
        sb.append(", color=").append(color);
        sb.append('}');
        return sb.toString();
    }
}
